<?php
/**
 * Created by PhpStorm.
 * User: zcq
 * Date: 2018/10/22
 * Time: 16:46
 */

namespace app\index\model;


use app\common\RedisCache;

class Comment extends BaseModel
{
    //是否显示
    const ENABLE_TRUE = 1;
    const ENABLE_FALSE = 0;

    //自动审核是否通过
    const AUTO_TRUE = 1;
    const AUTO_FALSE = 2;
    const AUTO_NO_CHECK = 3;

    public static function getList($voteItemId)
    {
        $key = 'comment_'.$voteItemId;
        $expire = 7*24*3600;
        $data = RedisCache::getInstance()->cache($key);
        if($data !== false){
            $data = json_decode($data,1);
        }else{
            $data = self::where('vote_item_id',$voteItemId)
                ->where('enable',self::ENABLE_TRUE)
                ->order('id desc')
                ->field('id,vote_id,mid,mobile,ip,content,addtime')
                ->select();
            RedisCache::getInstance()->cache($key,json_encode($data,JSON_UNESCAPED_UNICODE),$expire);
        }

        return $data;
    }
}